<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    print_r($data);
    if (isset($data['content'])) {
        $content = $data['content'];
        $result = file_put_contents('file.txt', $content);

        if ($result === false) {
            echo json_encode(['error' => 'Failed to write content to file']);
            exit;
        }

        // 记录操作日志
        $logMessage = '[' . date('Y-m-d H:i:s') . '] ' . $data['username'] . ' 更新了文件内容';
        file_put_contents('log.txt', $logMessage . PHP_EOL, FILE_APPEND);
    }

    if (isset($data['username'])) {
        // 更新用户名
        $username = $data['username'];

        // 记录操作日志
        $logMessage = '[' . date('Y-m-d H:i:s') . '] ' . $data['oldUsername'] . ' 修改了用户名为 ' . $username;
        file_put_contents('log.txt', $logMessage . PHP_EOL, FILE_APPEND);
    }
}
?>
